/*!
    \file  tft_test.c
    \brief tft lcd test functions
*/

/*
    Copyright (C) 2016 GigaDevice

    2016-01-15, V1.0.0, demo for GD32F1x0(x=3,5)
    2016-05-13, V2.0.0, demo for GD32F1x0(x=3,5)
*/

#include "lcd_driver.h"
#include "gui.h"
#include "delay.h"
#include "tft_test.h"
#include "string.h"

unsigned char num[10] = {0,1,2,3,4,5,6,7,8,9};
tft_test_s tft_test = {.state = 0};
/*!
    \brief      number display test
    \param[in]  none
    \param[out] none
    \retval     none
*/
void num_test(void)
{
    uint8_t i = 0;
    lcd_clear(BLUE);
    gui_draw_font_gbk24(16,20,YELLOW,BLUE,"Num Display Test");

    for(i = 0;i < 10;i ++){
        gui_draw_font_num32(50 + (i % 3) * 40,32 * (i / 3) + 50,WHITE,BLUE,num[i + 1]);
        delay_ms(100);
    }

    delay_ms(1000);
}

void num_test2(void)
{
    uint8_t i = 0;
    lcd_clear(BLUE);
    gui_draw_font_gbk24(16,20,YELLOW,BLUE,"Num Display Test");

    for(i = 0;i < 10;i ++){
        gui_draw_font_num32(50 + (i % 3) * 40,32 * (i / 3) + 50,WHITE,BLUE,num[i + 1]);
        // delay_ms(100);
    }

    // delay_ms(1000);
}

/*!
    \brief      font display test
    \param[in]  none
    \param[out] none
    \retval     none
*/
void font_test(void)
{
    __O  uint8_t x_offset;

#ifdef H_VIEW
    x_offset = 40;
#else
    x_offset = 0;
#endif

    lcd_clear(BLUE);

    /* lcd display mcu informations */
    gui_draw_font_gbk16(2,10,WHITE,BLUE," GigaDevice Semiconductor Inc.");
    gui_draw_font_gbk16(2,30,WHITE,BLUE,"  -- GD32F1x0 Series MCU --   ");
    
    gui_draw_font_gbk16(2,50,WHITE,BLUE,"     GD32F150R_EAVL_V1.2  ");

    gui_draw_font_gbk16(x_offset,60 + 16,WHITE,BLUE,"     ---- GD32F130 ----      ");

    gui_draw_font_gbk16(x_offset,60 + 32,WHITE,BLUE,"         GD32F130Fx      ");
    gui_draw_font_gbk16(x_offset,60 + 48,WHITE,BLUE,"         GD32F130GX      ");
    gui_draw_font_gbk16(x_offset,60 + 64,WHITE,BLUE,"         GD32F130Cx      ");
    gui_draw_font_gbk16(x_offset,60 + 80,WHITE,BLUE,"         GD32F130Rx      ");

    gui_draw_font_gbk16(x_offset,80 + 96 ,WHITE,BLUE,"     ---- GD32F150 ----      ");
    gui_draw_font_gbk16(x_offset,80 + 112,WHITE,BLUE,"         GD32F150Fx       ");
    gui_draw_font_gbk16(x_offset,80 + 128,WHITE,BLUE,"         GD32F150KX       ");
    gui_draw_font_gbk16(x_offset,80 + 144,WHITE,BLUE,"         GD32F150Cx      ");
    gui_draw_font_gbk16(x_offset,80 + 160,WHITE,BLUE,"         GD32F150Rx      ");

    gui_draw_font_gbk24(x_offset,80 + 200,WHITE,BLUE,"  Smarter! Faster! Cheaper!  ");

    delay_ms(1000);

    /* lcd display Chinese characters */
    lcd_clear(BLUE);
    gui_draw_font_gbk16(16,10,WHITE,BLUE,"        测试   ");
    gui_draw_font_gbk24(16,30,WHITE,BLUE,"       测试   "); 

    gui_draw_font_gbk16(16,50,WHITE,BLUE,"        测试   ");
    gui_draw_font_gbk24(16,70,WHITE,BLUE,"       测试   "); 

    delay_ms(3000);
}

void font_test2_1(void)
{
    __O  uint8_t x_offset;

#ifdef H_VIEW
    x_offset = 40;
#else
    x_offset = 0;
#endif

    lcd_clear(BLUE);

    /* lcd display mcu informations */
    gui_draw_font_gbk16(2,10,WHITE,BLUE," GigaDevice Semiconductor Inc.");
    gui_draw_font_gbk16(2,30,WHITE,BLUE,"  -- GD32F1x0 Series MCU --   ");
    
    gui_draw_font_gbk16(2,50,WHITE,BLUE,"     GD32F150R_EAVL_V1.2  ");

    gui_draw_font_gbk16(x_offset,60 + 16,WHITE,BLUE,"     ---- GD32F130 ----      ");

    gui_draw_font_gbk16(x_offset,60 + 32,WHITE,BLUE,"         GD32F130Fx      ");
    gui_draw_font_gbk16(x_offset,60 + 48,WHITE,BLUE,"         GD32F130GX      ");
    gui_draw_font_gbk16(x_offset,60 + 64,WHITE,BLUE,"         GD32F130Cx      ");
    gui_draw_font_gbk16(x_offset,60 + 80,WHITE,BLUE,"         GD32F130Rx      ");

    gui_draw_font_gbk16(x_offset,80 + 96 ,WHITE,BLUE,"     ---- GD32F150 ----      ");
    gui_draw_font_gbk16(x_offset,80 + 112,WHITE,BLUE,"         GD32F150Fx       ");
    gui_draw_font_gbk16(x_offset,80 + 128,WHITE,BLUE,"         GD32F150KX       ");
    gui_draw_font_gbk16(x_offset,80 + 144,WHITE,BLUE,"         GD32F150Cx      ");
    gui_draw_font_gbk16(x_offset,80 + 160,WHITE,BLUE,"         GD32F150Rx      ");

    gui_draw_font_gbk24(x_offset,80 + 200,WHITE,BLUE,"  Smarter! Faster! Cheaper!  ");
}

void font_test2_2(void)
{
    /* lcd display Chinese characters */
    lcd_clear(BLUE);
    gui_draw_font_gbk16(16,10,WHITE,BLUE,"        测试   ");
    gui_draw_font_gbk24(16,30,WHITE,BLUE,"       测试   "); 

    gui_draw_font_gbk16(16,50,WHITE,BLUE,"        测试   ");
    gui_draw_font_gbk24(16,70,WHITE,BLUE,"       测试   "); 
}

/*!
    \brief      color display test
    \param[in]  none
    \param[out] none
    \retval     none
*/
void color_test(void)
{
    __O  uint8_t i=2;

    while(i--){
        /* lcd display color test */
        lcd_clear(WHITE);
        gui_draw_font_gbk16(20,50,BLACK,WHITE,"Color Display Test");
        gui_draw_font_gbk16(100,100,BLACK,WHITE,"White");
        delay_ms(1000);
        
        /* lcd display color test */
        lcd_clear(BLACK);
        gui_draw_font_gbk16(20,50,WHITE,BLACK,"Color Display Test");
        gui_draw_font_gbk16(100,100,WHITE, BLACK,"Black");
        delay_ms(1000);
       
        /* lcd display color test */
        lcd_clear(RED);
        gui_draw_font_gbk16(20,50,WHITE,RED,"Color Display Test");
        gui_draw_font_gbk16(100,100,WHITE,RED,"Red");
        delay_ms(1000);

        /* lcd display color test */
        lcd_clear(GREEN);
        gui_draw_font_gbk16(20,50,BLUE,GREEN,"Color Display Test");
        gui_draw_font_gbk16(100,100,BLUE,GREEN,"Green");
        delay_ms(1000);

        /* lcd display color test */
        lcd_clear(BLUE);
        gui_draw_font_gbk16(20,50,YELLOW,BLUE,"Color Display Test");
        gui_draw_font_gbk16(100,100,YELLOW,BLUE,"Blue");
        delay_ms(1000);

        /* lcd display color test */
        lcd_clear(YELLOW);
        gui_draw_font_gbk16(20,50,BLUE,YELLOW,"Color Display Test");
        gui_draw_font_gbk16(100,100,BLUE,YELLOW,"Yellow");
        delay_ms(1000);
    }
}

void color_test2(uint16_t color_fc, uint16_t color_bc, char *display)
{
    lcd_clear(color_bc);
    gui_draw_font_gbk16(20,50,color_fc,color_bc,"Color Display Test");
    gui_draw_font_gbk16(100,100,color_fc,color_bc, display);
}

/*!
    \brief      gui draw test
    \param[in]  none
    \param[out] none
    \retval     none
*/
void draw_test(void)
{
    __O  uint8_t i=0;

    lcd_clear(BLUE);
    gui_draw_font_gbk16(2,20,WHITE, BLUE,"  GUI Draw Test ");
    /* gui box */
    gui_box(60,90,160,160,GREEN);
    /* gui box2 */
    gui_box2(20,160,200,120,0);
    gui_box2(25,165,205,125,0);
    gui_box2(30,170,210,130,0);
    /* gui rect */
    gui_rect(10,50,110,70,YELLOW);
    /* gui circle */
    gui_circle(120,160,80,RED);
   
    delay_ms(1000);
}

void draw_test2(void)
{
    __O  uint8_t i=0;

    lcd_clear(BLUE);
    gui_draw_font_gbk16(2,20,WHITE, BLUE,"  GUI Draw Test ");
    /* gui box */
    gui_box(60,90,160,160,GREEN);
    /* gui box2 */
    gui_box2(20,160,200,120,0);
    gui_box2(25,165,205,125,0);
    gui_box2(30,170,210,130,0);
    /* gui rect */
    gui_rect(10,50,110,70,YELLOW);
    /* gui circle */
    gui_circle(120,160,80,RED);
}


void tft_test_func(void)
{
    switch(tft_test.state)
    {
        case 0:
            num_test2(); 
            break;

        case 1:
            font_test2_1();
            break;

        case 2:
            font_test2_2();
            break;

        case 3:
            color_test2(BLUE,YELLOW,"Yellow");
            break;     
        case 4:
            color_test2(BLACK,WHITE,"White");            
            break;

        case 5:
            color_test2(WHITE,BLACK,"Black");            
            break;

        case 6:
            color_test2(WHITE,RED,"Red");            
            break;

        case 7:
            color_test2(BLUE,GREEN,"Green");            
            break;

        case 8:
            color_test2(YELLOW,BLUE,"Blue");            
            break;
        
        case 9:
            draw_test2();
            break;

        default:
            break;
    }

	tft_test.state++;
    if(tft_test.state >= 10)
    {
        tft_test.state = 0;
    }        
}
